$(document).ready(function(){
    var pathname = window.location.pathname;
    var _dh_url = window.location.hostname;
    if(_dh_url != 'daohe.qianbudai.com' && _dh_url != 'baidu.qianbudai.com' && _dh_url != 'gz.qianbudai.com'){
        _dh_url = "tongji.daohemedia.com";
    }else{
        _dh_url = "daohe.qianbudai.com";
    }
    $(".call").on("click", function(){
      if(hotline){
        //统计
        var source = $.getUrlParam('source');
        var plan = $.getUrlParam('plan');
        var unit = $.getUrlParam('unit');
        var keyword = $.getUrlParam('keyword');
        var e_keywordid = $.getUrlParam('e_keywordid');
        var e_keywordid2 = $.getUrlParam('e_keywordid2');
        //http://tongji.daohemedia.com
        var browser =navigator.userAgent;
        var parent_url = window.parent.document.referrer
        $.ajax({
            url: "http://"+_dh_url+"/api/tongji/index",
            data: {
                name:pathname,
                source:source,
                plan:plan,
                unit:unit,
                keyword:keyword,
                e_keywordid:e_keywordid,
                e_keywordid2:e_keywordid2,
                // url: location.href,
                browser:browser,
                parent_url: parent_url,
                admin_id:4//广州
            },
            dataType: 'jsonp',
        });
        window.location.href = "tel:" + hotline;
      }
    });
    layer.config({
      skin: 'demo-class layui-bg-red'
    })
    $('#gotosave_bt').click(function(){
      var title = $('title').text();
      var plan = $.getUrlParam('plan');//璁″垝

      var pathname = window.location.pathname;
      var parent_url = window.parent.document.referrer
      var name = $('input[name="name"]').val();
      var phone = $('input[name="tele"]').val();
      var ret = /^1[3|4|5|6|7|8|9]\d{9}$/;
      if(name == ""){
          layer.msg('请输入您的姓名', {icon: 2});
          return false;
      }

      if(phone == "" || !ret.test(phone)){
          if(!ret.test(phone)){
              layer.msg('请输您的手机号', {icon: 2});
          }
          return false;
      }


      $.ajax({
          url:'http://'+_dh_url+'/api/yuyue/index',
          type:"POST",
          dataType:"json",
          data:{
            title:title,
            name:name,
            phone:phone,
            plan:plan,
            state:1,//0=默认,1=看房,2=留言,3=团购,4=特价房,5=项目咨询
            pathname:pathname,
            parent_url: parent_url,
            siteurl:_dh_url,
            admin_id:4//广州
          },
          beforeSend: function() {
             $('#gotosave_bt').text('提交中...');
          },
          error: function(request) {
            layer.msg(request.responseText, {icon: 2});
          },
          success:function(data){
              if(data.code != '1'){
                  layer.msg(data.error, {icon: 2});
              }else{
                  layer.msg("提交成功，稍后置业顾问会跟您联系。", {icon: 1});
                  $('input[name="name"]').val('');
                  $('input[name="tele"]').val('');
              }
              $('#gotosave_bt').text('立即报名');
          }
      });

    });

  });
$.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
